<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
    <title>后台首页</title>
    <link rel="stylesheet" href="__BOOTSTRAP__/css/bootstrap.css" />
    <link rel="stylesheet" href="__BOOTSTRAP__/css/bootstrap-rtl.css?ver=321" />
    <link rel="stylesheet" href="__LAYUI__/css/layui.css" />
    <link rel="stylesheet" href="__LAYER__/skin/default/layer.css?ver=4" />
    <script type="text/javascript" src="__JQUERY__/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="__BOOTSTRAP__/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="__LAYER__/layer.js" ></script>
    <script type="text/javascript" src="__JQUERY__/nur.js?ver=13"></script>
    <script type="text/javascript" src="__LAYUI__/layui.js"></script>
    <script type="text/javascript">
        function o_link() {
            if($('input[name="thumb"]').val() == ''){
                layer.alert(' رەسىم يوللاڭ！', {
                    title:"سېستىما ئەسكەرتىشى",
                    btn:"بىلدىم",
                    icon: 0,
                    skin: 'layer-ext-moon',
                    time:2000
                });
                return false;
            }
            _submit_source();
        }
        function _submit_source() {
            var id=url_str(window.location.href);
            var val_img=$('input[name="thumb"]').val();
            $.ajax({
                type:"post",
                url:"{:U('Menu/icon')}",
                dataType:"json",
                data:{"id":id,"thumb":val_img},
                success:function (phpdata) {
                    if(phpdata.status==1){
                        layer.alert(phpdata.message, {
                            title:"سېستىما ئەسكەرتىشى",
                            btn:"بىلدىم",
                            icon: 6,
                            skin: 'layer-ext-moon',
                            time:800
                        });
                        setTimeout(close,1000);
                        function close() {
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);
                        }
                    }else{
                        layer.alert(phpdata.message, {
                            title:"سېستىما ئەسكەرتىشى",
                            btn:"بىلدىم",
                            icon: 5,
                            skin: 'layer-ext-moon',
                            time:1000
                        });
                    }
                }
            })

        }
        $(function () {
            $(".photo_tuku img").click(function () {
                var src=$(this).attr("src");
                $("#thumb",window.parent.document).val(src);
                $("#thumbface",window.parent.document).show();
                $("#thumbface",window.parent.document).attr("src",src);
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });
        })
    </script>
    <style>
        .source{
            margin-top: 30px;
            list-style: none;
            padding: 0;
        }
    </style>
</head>
<body>
    <div class="source col-md-6">
       <div class="panel panel-default" style="margin: 0 15px">
                <div class="panel-heading" style="font-size: 15px"> ئايكون رەسىم قوشۇش</div>
                <div class="panel-body">
                    <button type="button" class="layui-btn pull-left" id="test1">
                        <i class="layui-icon"></i>رەسىم يوللاش
                    </button>
                    <input id="thumb" style="width: 50%;margin-right: 6px"  name="thumb" class="form-control" />
                    <br>
                    <img style="display: none;height: 70px;width: 70px;" id="thumbface" src="" />
                </div>
                <script>
                    layui.use('upload', function(){
                        var upload = layui.upload;
                        //执行实例
                        var uploadInst = upload.render({
                            elem: '#test1' //绑定元素
                            ,url: '{:U("Article/source_uploads")}' //上传接口
                            ,done: function(res){
                                //上传完毕回调
                                if(res.status == 1){
                                    layer.alert(res.message, {
                                        title:"سېستىما ئەسكەرتىشى",
                                        btn:"بىلدىم",
                                        icon: 6,
                                        skin: 'layer-ext-moon',
                                        time:500
                                    });
                                    $("#thumb").val(res.src) ;
                                    $("#thumbface").css("display","block") ;
                                    $("#thumbface").attr("src","/"+res.src) ;
                                }else{
                                    layer.alert(res.message, {
                                        title:"سېستىما ئەسكەرتىشى",
                                        btn:"بىلدىم",
                                        icon: 5,
                                        skin: 'layer-ext-moon',
                                        time:1000
                                    });
                                }
                            }
                            ,error: function(){
                                //请求异常回调
                            }
                        });
                    });
                </script>
            </div>
        <br>
        <a href="javascript:o_link()" style="width: 150px;display: block;margin: auto"  class="btn btn-primary">قوشۇش</a>
    </div>
</body>
</html>